package com.whccb.apps.office.document.event;

import java.util.Calendar;
import java.util.Map;

import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener;
import com.actionsoft.bpms.bpmn.engine.listener.ListenerConst;

public class UseRedHeaderTaskFormAfterLoadEvent extends ExecuteListener {

	public String getDescription() {
		return "公文发文流程，套红节点表单加载后，初始化参数";
	}

	public String getProvider() {
		return "ActionSoft";
	}

	public String getVersion() {
		return "AWS 6.0";
	}

	public void execute(ProcessExecutionContext param) throws Exception {
		Map<String, Object> macroLibraries = param
				.getParameterOfMap(ListenerConst.FORM_EVENT_PARAM_TAGS);
		if (macroLibraries.get("FILETIME") != null) {
			String fileTime = "<input type='text'   class='txt'  readonly='readonly'  placeholder='' name='FILETIME' id='FILETIME'  value='"
					+ getGWNowDateStr() + "' >";
			macroLibraries.put("FILETIME", fileTime);
		}
		if (macroLibraries.get("CONTENTTIME") != null) {
			String contentTime = "<input type='text'   class='txt'  readonly='readonly'  placeholder='' name='CONTENTTIME' id='CONTENTTIME'  value='"
					+ getGWNowDateStr() + "' >";
			macroLibraries.put("CONTENTTIME", contentTime);
		}
	}

	public String getGWNowDateStr() {
		int y, m, d;
		Calendar cal = Calendar.getInstance();
		y = cal.get(Calendar.YEAR);// 年
		m = cal.get(Calendar.MONTH) + 1;// 月
		d = cal.get(Calendar.DATE); // 日
		return String.valueOf(y) + "年" + String.valueOf(m) + "月"
				+ String.valueOf(d) + "日";
	}
}
